<?php

	function get_musics($navpath="/Library/") {
		global $MPD;
		$html = '';
		$html .= '<div id="musics_list">';
	
		$html .= '<div id="music_path2">';
		$navpath = ltrim ($navpath, '/');
		$navpath = rtrim ($navpath, '/');
		$path_explode = explode('/', $navpath );

		for($j=0;$j<count($path_explode);$j++) {
			$url = '/';
			for($i=0;$i<count($path_explode);$i++) {
				$url .= $path_explode[$i]."/";
				if ($i == $j) break;
			}
			$html .= '<a onclick="javascript:load_folder(\''.$url.'\', withPath=false)">'.$path_explode[$j].'</a> > ';
		}
		$html .= '</div>';
		$html .= '<div id="music_path">'.$url.$path_explode[$j].'</div>';


		$html .= '<div id="musics_list2">';

		if ( is_null( $folders = $MPD->listDir($navpath) ) ) return null;
		foreach ($folders as $key=>$value) {
			if ($value=='directory' ) {
				$html .= '<div id="music_item">';
				$html .= '<div class="music_item_left" onclick="javascript:load_folder(\''.addslashes($key).'\')">'.$key.'</div>';
				$html .= '<ul><li><img src="images/play.png" onclick="javascript:play_folder(\''.addslashes($key).'\')" /></li>';
				$html .= '<li><img src="images/random.png" onclick="javascript:play_folder(\''.addslashes($key).'\', random=true)" /></li>';
				$html .= '</ul>';
				$html .= '<div class="music_item_both"></div>';
				$html .= '</div>';
			}
			if ($value=='file' ) {
				$html .= '<div id="music_item_file">';
				$html .= '<div class="music_item_file" onclick="javascript:play_file(\''.addslashes($key).'\')">'.$key.'</div>';
				$html .= '</div>';
			}
		}
		$html .= '</div>';
		$html .= '</div>';
		return $html;
	}
?>

